package com.hkts.naturalgas.flow.controller;


import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hkts.naturalgas.flow.entity.FlowNodeinfo;
import com.hkts.naturalgas.flow.service.IFlowNodeinfoService;
import com.hkts.naturalgas.utils.CustomPageUtils;
import com.hkts.naturalgas.utils.Result;
import com.hkts.naturalgas.utils.ResultUtil;
import org.mybatis.logging.Logger;
import org.mybatis.logging.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author zy
 * @since 2022-08-31
 */
@RestController
@RequestMapping("/performance/flowNodeinfo")
public class FlowNodeinfoController {
    private final Logger logger = LoggerFactory.getLogger(FlowNodeinfoController.class);

    @Autowired
    public IFlowNodeinfoService iFlowNodeinfoService;

    /**
     * 分页查询数据
     *
     * @param page         分页信息
     * @param flowNodeinfo 查询条件
     * @return
     */
    @ResponseBody
    @GetMapping("/getFlowNodeinfoPageList")
    public Result<Object> getHontUserList(Page<FlowNodeinfo> page, FlowNodeinfo flowNodeinfo) {
        return ResultUtil.data(CustomPageUtils.getCustomPage(iFlowNodeinfoService.selectPage(page, flowNodeinfo)));
    }

    /**
     * 保存和修改公用的
     *
     * @param flowNodeinfo 传递的实体
     * @return saveOrUpdate
     */
    @ResponseBody
    @RequestMapping(method = RequestMethod.POST, value = "/flowNodeinfoSave")
    public Result<Object> flowNodeinfoSave(FlowNodeinfo flowNodeinfo) {
        iFlowNodeinfoService.saveOrUpdate(flowNodeinfo);
        return ResultUtil.success("保存成功");
    }

    /**
     * 根据id获取对象
     *
     * @param id 实体ID
     * @return 0 失败  1 成功
     */
    @ResponseBody
    @RequestMapping(method = RequestMethod.GET, value = "/flowNodeinfoGetById")
    public Result<Object> flowNodeinfoGetById(String id) {
        FlowNodeinfo byId = iFlowNodeinfoService.getById(id);
        return ResultUtil.data(byId);
    }

    /**
     * 根据id删除对象
     *
     * @param id 实体ID
     * @return 0 失败  1 成功
     */
    @ResponseBody
    @RequestMapping(method = RequestMethod.POST, value = "/flowNodeinfoDelete")
    public Result<Object> hontUserDelete(String id) {
        iFlowNodeinfoService.removeById(id);
        return ResultUtil.success("删除成功");
    }

    /**
     * 批量删除对象
     *
     * @param item 实体集合ID
     * @return 0 失败  1 成功
     */
    @ResponseBody
    @RequestMapping(method = RequestMethod.POST, value = "/flowNodeinfoBatchDelete")
    public Result<Object> deleteBatchIds(String item) {
        List<String> ids = (List<String>) JSON.parse(item);
        iFlowNodeinfoService.removeByIds(ids);
        return ResultUtil.success("删除成功");
    }
    /**
     * 功能描述: <br>
     * 〈〉根据模板id获取节点信息
     * @Param: [templateId]
     * @Return: cn.exrick.xboot.common.vo.Result<java.lang.Object>
     * @Author: zhangyong
     * @Date: 2022/9/13 上午10:13
     */
    @ResponseBody
    @RequestMapping(method = RequestMethod.POST, value = "/getFlowNodeinfo")
    public Result<Object> getFlowNodeinfo(String templateId,String templateVersion) {

        return ResultUtil.data(iFlowNodeinfoService.getFlowNodeinfoVo(templateId,templateVersion));
    }


}
